﻿using KAKA.Domain;
using KAKA.Repository;
using Morus;
using Morus.Infrastructure;

namespace KAKA.Infrastructure
{
    public class DefaultUser : IBootstrapperTask
    {
        public string Email { get; private set; }
        public string Password { get; private set; }
        public string Nickname { get; private set; }
        public Role Role { get; private set; }

        public DefaultUser(string email, string password, string nickname, Role role)
        {
            Email = email;
            Password = password;
            Nickname = nickname;
            Role = role;
        }

        public void Execute()
        {
            using (var userRepository = IoC.Resolve<IUserRepository>())
            {
                var user = userRepository.Get(Email);
                if (user == null)
                {
                    user = User.Create(Email, Password, Gender.None.ToString(), Nickname);
                    user.Role = Role;
                    user.EmailVerified = true;
                    userRepository.Add(user);
                    userRepository.Commit();
                }
            }
        }
    }
}